<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>${tabTitle}</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style>
        .sq-button-dis{
            background: #999999!important;
            cursor: not-allowed;
            pointer-events: none;
        }
    </style>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div>
        <div id="pageInTab" class="pageInTab">
            <form id="ins_cfg_info_edit_form">
                <div class="fieldset1 tabel_col clearFix">
                    <div class="fieldBox col_33">
                        <div class="label">机构名称</div>
                        <div class="field">
                            <span>${fundRasInsNm}</span>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">企业名称</div>
                        <div class="field">
                            <span>${cstNm}</span>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">证件类型</div>
                        <div class="field">
                            <span>${certTypCdNm}</span>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">证件号</div>
                        <div class="field">
                            <span>${certNo}</span>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">法人姓名</div>
                        <div class="field">
                            <span>${mNm}</span>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">身份证号</div>
                        <div class="field">
                            <span>${mCertNo}</span>
                        </div>
                    </div>
                    <c:if test="${certTypCd == 'b'}">
                        <div class="fieldBox col_33">
                            <div class="label">证件类型</div>
                            <div class="field">
                                <select name="bcCertTypCd" id="bcCertTypCd">
                                    <option value="">--请选择--</option>
                                    <option value="a" <c:if test="${bcCertTypCd == 'a'}">selected = "selected"</c:if>>组织机构代码证</option>
                                    <option value="91" <c:if test="${bcCertTypCd == '91'}">selected = "selected"</c:if>>社会统一信用代码</option>
                                </select>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">证件编号</div>
                            <div class="field">
                                <input name="bcCertNo" id="bcCertNo" type="text" class="ui-textbox" value="${bcCertNo}">
                            </div>
                        </div>
                    </c:if>
                    <c:if test="${prjTypCd == 'CPYW'}">
                        <div class="fieldBox col_33">
                            <div class="label">开户银行</div>
                            <div class="field">
                                <span>中国建设银行</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">账户类型</div>
                            <div class="field">
                                <select name="accTypCd" id="accTypCd" data-value="" validate="{required:true, select: true}">
                                    <option value="">--请选择--</option>
                                    <option value="0100" <c:if test="${accTypCd == '0100'}">selected = "selected"</c:if>>对公账户</option>
                                    <option value="0200" <c:if test="${accTypCd == '0200'}">selected = "selected"</c:if>>个人账户</option>
                                </select>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">银行卡号</div>
                            <div class="field">
                                <input name="accNo" id="accNo" type="text" class="ui-textbox" value="${accNo}"
                                       validate="{number:true, maxlength:22, minlength:15}">
                            </div>
                        </div>
                    </c:if>
                    <div class="fieldBox col_100">
                        <div class="label">准入结果</div>
                        <div class="field"  style="width:100%;">
                            <textarea name="result" id="result" rows="4" class="ui-textarea l-textarea" style="width:99%" value="" disabled="disabled"></textarea>
                        </div>
                    </div>

                    <!-- hide data -->
                    <div class="fieldBox col_100" style="display: none;">
                        <div class="field">
                            <input name="insCode" id="insCode" type="text" class="ui-textbox" value="${insCode}">
                            <input name="prjId" id="prjId" type="text" class="ui-textbox" value="${prjId}">
                            <input name="cstId" id="cstId" type="text" class="ui-textbox" value="${cstId}">
                            <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="${cstNm}">
                            <input name="cstAccInfoId" id="cstAccInfoId" type="text" class="ui-textbox" value="${cstAccInfoId}">
                            <input name="fundRasInsId" id=fundRasInsId type="text" class="ui-textbox" value="${fundRasInsId}">
                            <input name="loanCardCd" id=loanCardCd type="text" class="ui-textbox" value="${loanCardCd}">
                        </div>
                    </div>
                </div>
                <div id="saveInsCfgDiv" class="btnsBox">
                    <sys:FlowFrmAth preTaskIds="${preTaskIds}" athCd="addPrjBscInfo" pInstId="${pInstId}">
                        <span id="saveInsCfg" class="sq-button sq-button-round sq-button-dis" onclick="saveInfo();">建行准入</span>
                    </sys:FlowFrmAth>
                </div>
                <div class="fieldBox col_100" id="picture">
                    <div class="sqPanel">
                        <table class="table_full tbl_1">
                            <tr>
                                <td>
                                    <div class="field">
                                        <img src="${picture}" alt="深圳建行平台云贷" name="picture"/>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">

    var detailFlag = '${detailFlag}';
    var updateFlag = '${updateFlag}';
    var fromCAFlag = '${fromCAFlag}';
    var fromCMFlag = '${fromCMFlag}';
    var certTypCd = '${certTypCd}';
    var prjTypCd = '${prjTypCd}';
    var accResCd = '${accResCd}';
    var accResMsg = '${accResMsg}';

    $(function () {
        initData();
    });

    function initData() {
        $("#ins_cfg_info_edit_form").ligerForm({
            validate: true
        });
        $("#picture").hide();
        $("#result").setDisabled_ligerTextarea(true);
        if (accResCd == '' ){
            $('#saveInsCfg').removeClass('sq-button-dis');
        }
        disabledInput();
        enableFields();
    }

    function enableFields() {
        if (null != fromCAFlag && "true" == fromCAFlag) {
            $("#saveInsCfgDiv").show();
        }
        if (null != fromCMFlag && "true" == fromCMFlag) {
            $("#saveInsCfgDiv").show();
        }
    }

    function disabledInput() {
        if (detailFlag == "true") {
            if (liger.get("bcCertTypCd")){
                liger.get("bcCertTypCd").setDisabled(true);
            }
            if (liger.get("bcCertNo")){
                liger.get("bcCertNo").setDisabled(true);
            }
            $("#saveInsCfgDiv").hide();
        }
        if (accResCd == '1') {
            $("#saveInsCfg").addClass("sq-button-dis");
            $("#picture").show();
            $("#result").val('准入成功后才可联系客户通过建行小程序签署征信授权书\n' +
                '准入成功，请联系客户经理登陆建行小程序签署征信授权书，客户签署完成后再发起项目评审流程\n' +
                '如果客户小程序签署失败，则是征信不通过，请提前切换其他资方');
        } else if (accResCd == '0') {
            $("#saveInsCfg").removeClass("sq-button-dis");
            $("#picture").hide();
            $("#result").val('准入成功后才可联系客户通过建行小程序签署征信授权书\n' +
                '准入失败，失败原因：' + accResMsg + '\n' + '请核实信息重新准入，或选择其他资方');
        } else {
            $("#picture").hide();
        }
    }

    // 保存项目客户信息，后面弹出准入验证的资料确认页
    function saveInfo() {
        var ligerForm = liger.get("ins_cfg_info_edit_form");
        var data = ligerForm.getData();
        if (certTypCd == 'b') {
            if (!$("#bcCertTypCd").val()) {
                top.$.ligerDialog.SQalert({content: "请选择证件类型！", SQ_type: "error"});
                return false;
            }
            if (!$("#bcCertNo").val()) {
                top.$.ligerDialog.SQalert({content: "请填写证件编号！", SQ_type: "error"});
                return false;
            }
        }
        if (prjTypCd == 'CPYW') {
            if(!$("#accNo").val()){
                top.$.ligerDialog.SQalert({content: "请填写银行账号！", SQ_type: "error"});
                return false;
            }
            if(!$("#accTypCd").val()){
                top.$.ligerDialog.SQalert({content: "请选择账户类型！", SQ_type: "error"});
                return false;
            }
        }
        data["certTypCd"] = '${certTypCd}';
        data["certNo"] = '${certNo}';
        data["insCode"] = $("#insCode").val();
        data["prjId"] = $("#prjId").val();
        data["cstId"] = $("#cstId").val();
        data["cstNm"] = $("#cstNm").val();
        data["fundRasInsId"] = $("#fundRasInsId").val();
        data["fundRasInsNm"] = '${fundRasInsNm}';
        data["cstAccInfoId"] = $("#cstAccInfoId").val();
        data["mCertNo"] = '${mCertNo}';//法人身份证号
        data["mNm"] = '${mNm}';//法人姓名
        data["loanCardCd"] = $("#loanCardCd").val();//中征码
        data["bcCertTypCd"] = $("#bcCertTypCd").val();//补充证件类型：组织机构代码||统一社会信用代码
        data["bcCertNo"] = $("#bcCertNo").val();//补充证件号
        data["accNo"] =  $("#accNo").val();//银行卡号
        data["accTypCd"] = $("#accTypCd").val();//账户类型

        var url = '<%=path%>/institution/ccbanktb/submitCredit.do';
        var wait_dialog;
        $.ajax({
            type: 'get',
            dataType: 'json',
            data: data,
            url: url,
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                //新增时赋值
                if ($("#cstAccInfoId").val() == "" && msg.data != null ) {
                    $("#cstAccInfoId").val(msg.data);
                }
                if (msg.success == 1) {
                    if (liger.get("bcCertTypCd")){
                        liger.get("bcCertTypCd").setDisabled(true);
                    }
                    if (liger.get("bcCertNo")){
                        liger.get("bcCertNo").setDisabled(true);
                    }
                    $("#saveInsCfg").addClass("sq-button-dis");
                    $("#picture").show();
                    $("#result").val('准入成功后才可联系客户通过建行小程序签署征信授权书\n' +
                        '准入成功，请联系客户经理登陆建行小程序签署征信授权书，客户签署完成后再发起项目评审流程\n' +
                        '如果客户小程序签署失败，则是征信不通过，请提前切换其他资方');
                    UIUtils.alertSuccessHold1(msg.info);
                } else {
                    $("#picture").hide();
                    $("#result").val('准入成功后才可联系客户通过建行小程序签署征信授权书\n' +
                        '准入失败，失败原因：' + msg.info + '\n' + '请核实信息重新准入，或选择其他资方');
                    UIUtils.alertErrorHold1(msg.info);
                }
            }
        });
    }
</script>
</body>
</html>